package com.bocloud.cmp.driver.providers.impl;

import org.springframework.stereotype.Service;

import com.bocloud.cmp.driver.config.Configuration;
import com.bocloud.cmp.driver.providers.ObjectDriver;
import com.bocloud.cmp.driver.providers.intf.ObjectProvider;
import com.bocloud.cmp.driver.providers.jd.JdObjectDriver;
import com.bocloud.cmp.driver.utils.VendorConverter;
import com.bocloud.cmp.enums.VendorType;
import com.bocloud.cmp.model.Butler;
import com.bocloud.common.model.BsmResult;

@Service("objectProvider")
public class ObjectProviderImpl implements ObjectProvider {

	@Override
	public BsmResult exists(String bucket, String object, String vendor, String region) {
		BsmResult result = null;
		Butler butler = Configuration.instance().getConfig(vendor);
		VendorType type = VendorConverter.convert(butler.getCategory());
		switch (type) {
		case JDYUN:
			ObjectDriver driver = new JdObjectDriver(butler.getAccessKey(), butler.getSecretKey(), butler.getUrl(),
					region);
			result = driver.exists(bucket, object);
			break;
		case ALIYUN:
			break;
		default:
			break;
		}
		return result;
	}

	@Override
	public BsmResult remove(String bucket, String object, String vendor, String region) {
		BsmResult result = null;
		Butler butler = Configuration.instance().getConfig(vendor);
		VendorType type = VendorConverter.convert(butler.getCategory());
		switch (type) {
		case JDYUN:
			ObjectDriver driver = new JdObjectDriver(butler.getAccessKey(), butler.getSecretKey(), butler.getUrl(),
					region);
			result = driver.remove(bucket, object);
			break;
		case ALIYUN:
			break;
		default:
			break;
		}
		return result;
	}

	@Override
	public BsmResult detail(String bucket, String object, String vendor, String region) {
		BsmResult result = null;
		Butler butler = Configuration.instance().getConfig(vendor);
		VendorType type = VendorConverter.convert(butler.getCategory());
		switch (type) {
		case JDYUN:
			ObjectDriver driver = new JdObjectDriver(butler.getAccessKey(), butler.getSecretKey(), butler.getUrl(),
					region);
			result = driver.detail(bucket, object);
			break;
		case ALIYUN:
			break;
		default:
			break;
		}
		return result;
	}

	@Override
	public BsmResult list(String bucket, String vendor, String region) {
		BsmResult result = null;
		Butler butler = Configuration.instance().getConfig(vendor);
		VendorType type = VendorConverter.convert(butler.getCategory());
		switch (type) {
		case JDYUN:
			ObjectDriver driver = new JdObjectDriver(butler.getAccessKey(), butler.getSecretKey(), butler.getUrl(),
					region);
			result = driver.list(bucket);
			break;
		case ALIYUN:
			break;
		default:
			break;
		}
		return result;
	}

}
